#ifndef __COMMAND_H__
#define __COMMAND_H__
#include <iostream>
#include <list>
#include <algorithm>
/// @brief 烧烤者
class Barbecuer
{
public:
    /// @brief 烤羊肉串
    void RoastMuttonShashlik()
    {
        std::cout << "烤羊肉串\n";
    }
    void RoastChickenWing()
    {
        std::cout << "烤鸡翅\n";
    }
};
/// @brief 命令抽象类
class Command
{
protected:
    Barbecuer *m_pBarbecuer{}; // 烧烤者

public:
    Command(Barbecuer *pBarbecuer)
        : m_pBarbecuer(pBarbecuer) {}
    /// @brief 执行命令
    virtual void Execute() = 0;
};
/// @brief 烤羊肉串指令
class MuttonShashlikCommand : public Command
{
public:
    MuttonShashlikCommand(Barbecuer *pBarbecuer)
        : Command(pBarbecuer)
    {
    }
    virtual void Execute() override
    {
        m_pBarbecuer->RoastMuttonShashlik();
    }
};
/// @brief 烤鸡翅指令
class ChickenWingCommand : public Command
{
public:
    ChickenWingCommand(Barbecuer *pBarbecuer)
        : Command(pBarbecuer)
    {
    }
    virtual void Execute() override
    {
        m_pBarbecuer->RoastChickenWing();
    }
};
/// @brief 服务员
class Waiter
{
private:
    std::list<Command *> m_coms;

public:
    /// @brief 添加记录
    void AddRecord(Command *com)
    {
        m_coms.push_back(com);
    }
    /// @brief 移除记录
    void RemoteRecord(Command *com)
    {
        auto it = std::find(m_coms.begin(), m_coms.end(), com);
        if (it != m_coms.end())
            m_coms.erase(it);
    }
    /// @brief 通知
    void Notify()
    {
        for (auto it : m_coms)
            it->Execute();
    }
};

#endif